<template>
    <div class="parent">
        <h1>父组件</h1>
        <h2>子组件传来的参数：{{ sonData }}</h2>
        <Son/>
    </div>
</template>

<script lang="ts">
export default {
name:'Parent'
}
</script>

<script setup lang="ts">
import Son from './Son.vue';
import { onUnmounted, ref } from 'vue';
import emitter from '@/utils/emitter';

let sonData = ref('')

//绑定事件（订阅）
emitter.on('send-son', (value:any) => { 
    console.log('调用了', value);
    sonData.value = value
    
})

//组件卸载
onUnmounted(() => {
    console.log('解绑事件')
    //解绑所有事件
    emitter.all.clear()
})

</script>

<style lang="css">
.parent{
    width: 500px;
    height: 300px;
    background-color:aqua;
}
</style>